import axios from "axios"
import {getToken} from "@/utils/validate"
import {Message} from "element-ui";


// axios-2
const service = axios.create({
    baseURL: '/svc',
    timeout: 5000,
})

// 请求拦截
service.interceptors.request.use(( config) => {
    config.headers['token'] = getToken('token')
    return config
}, error => {
    return Promise.reject(error)
})

// 响应拦截
service.interceptors.response.use((response) => {
    if (response.data.code !== 200) {
        Message({message: response.data.msg || 'error', type: 'success'})
    }
    return response
}, error => {
    return Promise.reject(error)
})

export default service